package com.amigo.online.provider.video.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

import com.amigo.online.provider.video.interceptor.DispensableTokenInterceptor;
import com.amigo.online.provider.video.interceptor.TokenInterceptor;


@Configuration
public class AmigoWebMvcConfiguration extends WebMvcConfigurationSupport {

    @Bean
    public TokenInterceptor getTokenInterceptor() {
        return new TokenInterceptor();
    }

    @Bean
    public DispensableTokenInterceptor getDispensableTokenInterceptor() {
        return new DispensableTokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration ir = registry.addInterceptor(getTokenInterceptor());
        ir.addPathPatterns("/**").order(3);
        ir.excludePathPatterns("/user/getAll/**");
        ir.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
        ir.excludePathPatterns("/error/**", "/error");
		/*List<String> patterns = new ArrayList<>();
		patterns.add("/video/user/videos/**");	//用户上传的视频
		patterns.add("/video/recommended/**");	//推荐视频
		patterns.add("/video/user/uped/list/**");	//用戶喜欢(点赞)的视频列表
		patterns.add("/video/concern");		//关注者的视频
		patterns.add("/video/near/**");		//附近的视频	 
		registry.addInterceptor(getTokenInterceptor()).addPathPatterns("/**").excludePathPatterns(patterns).order(3);
		registry.addInterceptor(getDispensableTokenInterceptor()).addPathPatterns(patterns).order(4);
*/
    }

    /**
     * 加上swagger的地址
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");

    }
}